package com.meida.boot.handler.company;

import com.meida.common.mybatis.entity.EntityMap;
import com.meida.common.mybatis.interceptor.GetInterceptor;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.common.security.OpenHelper;
import com.meida.common.utils.FlymeUtils;
import com.meida.module.system.client.entity.SysCompany;
import com.meida.common.enums.ColleconEnum;
import com.meida.module.system.provider.service.SysColleconService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 企业详细信息处理器
 */
@Component("comapnyGetHandler")
@Log4j2
public class ComapnyGetHandler implements GetInterceptor {
    @Autowired
    private SysColleconService colleconService;

    /**
     * 查询条件扩展
     *
     * @param cq
     * @return
     */
    @Override
    public void prepare(CriteriaQuery cq, EntityMap params) {
        Long companyId = OpenHelper.getCompanyId();
        if (FlymeUtils.isNotEmpty(companyId)) {
            cq.eq(true, "companyId", companyId);
        }


    }

    /**
     * 返回结果集扩展
     *
     * @param cq
     * @return
     */
    @Override
    public void complete(CriteriaQuery cq, EntityMap map) {
        //此处添加自定义返回结果
//        map.put("tttttttttttttttt", "我是扩充进来的");
        Long companyId = map.getLong("companyId");
        //企业收藏标记
        Integer companyColleconTag = colleconService.countCollecon(companyId, ColleconEnum.SC, SysCompany.class);
        map.put("companyColleconTag", companyColleconTag);
    }
}
